#ifndef DEVICEPANEL_H
#define DEVICEPANEL_H

#include <QWidget>
#include <QVBoxLayout>
#include <QGroupBox>
#include <QSpinBox>
#include <QPushButton>
#include <QButtonGroup>

// 云台控制命令枚举
enum MoveCommand {
    // 方向控制
    CAMERA_UP,
    CAMERA_DOWN,
    CAMERA_LEFT,
    CAMERA_RIGHT,
    CAMERA_LEFT_UP,
    CAMERA_RIGHT_UP,
    CAMERA_LEFT_DOWN,
    CAMERA_RIGHT_DOWN,
    // 变焦控制
    CAMERA_ZOOM_OUT,
    CAMERA_ZOOM_IN,
    // 聚焦控制
    CAMERA_FOCUS_IN,
    CAMERA_FOCUS_OUT,
    // 停止
    CAMERA_STOP
};

class DevicePanel : public QWidget
{
    Q_OBJECT

public:
    explicit DevicePanel(QWidget *parent = nullptr);
    ~DevicePanel();

    // 设置云台控制URL
    void setCameraControlUrl(const QString &url);
    // 设置云台速度
    void setCameraSpeed(int speed);
    // 设置通道ID
    void setCameraChannelId(uint32_t channelId);

private:
    // 创建云台控制界面
    void createCameraControlUI();

    QPushButton *btnUp, *btnDown, *btnLeft, *btnRight;
    QPushButton *btnLeftUp, *btnLeftDown, *btnRightUp, *btnRightDown;
    QPushButton *btnZoomIn, *btnZoomOut;
    QPushButton *btnFocusIn, *btnFocusOut;

    QButtonGroup* cameraControlButtonGroup;

    QVBoxLayout* mainLayout;

    QString cameraControlUrl;
    int cameraSpeed = 67;
    uint32_t cameraChannelId = 1;

    // 命令字符映射
    static const char moveCommandValues[14];

private slots:

    // 处理按钮按下
    void handleButtonPressed();
    // 处理按钮释放
    void handleButtonReleased();

    QString getMoveUrl(MoveCommand command);


signals:

    void recordinfo(const QString &time, const QString &msg);

    // 发送云台控制命令
    // 参数: direction - 移动方向
    // 参数: action - 操作类型（移动、变倍等）
    void ptzCommand(QString command);
};

#endif // DEVICEPANEL_H
